Skip to content

fix randomgrowth.jl#50

Open
shashi wants to merge 3 commits intoJuliaMath:masterfrom
shashi:s/fix-randomgrowth
Open

fix randomgrowth.jl#50
shashi wants to merge 3 commits intoJuliaMath:masterfrom
shashi:s/fix-randomgrowth

Conversation

@shashi
Copy link

@shashi shashi commented Sep 9, 2019

This is a julia bug?

julia> G = rand(100,100);

julia> G[G .== 0.5] = 1
ERROR: MethodError: no method matching setindex_shape_check(::Int64, ::Int64)
Closest candidates are:
  setindex_shape_check(::AbstractArray{#s72,1} where #s72, ::Integer) at indices.jl:218
  setindex_shape_check(::AbstractArray{#s72,1} where #s72, ::Integer, ::Integer) at indices.jl:221
  setindex_shape_check(::AbstractArray{#s72,2} where #s72, ::Integer, ::Integer) at indices.jl:225
  ...
Stacktrace:
 [1] macro expansion at ./multidimensional.jl:694 [inlined]
 [2] _unsafe_setindex!(::IndexLinear, ::Array{Float64,2}, ::Int64, ::Base.LogicalIndex{Int64,BitArray{2}}) at ./multidimensional.jl:689
 [3] _setindex! at ./multidimensional.jl:684 [inlined]
 [4] setindex!(::Array{Float64,2}, ::Int64, ::BitArray{2}) at ./abstractarray.jl:1020
 [5] top-level scope at none:0

this patch includes a workaround.

@dlfivefifty
Copy link
Member

Great, though you can also do:

julia> G = rand(100,100);

julia> G[G .== 0.5] .= 1
0-element view(::Array{Float64,1}, Int64[]) with eltype Float64

@shashi
Copy link
Author

shashi commented Sep 9, 2019

Ah that's much better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments